# -*- coding:utf-8 -*-
import requests
from module.getgithubdata import GetData

class GithubSignUp():
    #cookie会话
    session = None

    def __init__(self):
        self.session = requests.Session()

    #注册



    # def join(self):
    #     code = self.session.get("https://github.com/join?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F&source=header-home").text
    #     get_data = GetData()
    #     token = get_data.getData(code,'<input type="hidden" data-csrf="true" name="authenticity_token" value=',' />')
    #     timestamp = get_data.getData(code,'<input class="form-control" type="hidden" name="timestamp" value=',' />')
    #     secret = get_data.getData(code,'<input class="form-control" type="hidden" name="timestamp_secret" value=',' />')
    #
    #     req = requests.post('https://github.com/join/',data = {
    #     'authenticity_token' : token,
    #     'user[login]' : 'usernnn1zz1',
    #     'user[email]' : '_7eh4489 @ meantinc.com',
    #     'user[password]' : '43WxpAap2eguetm',
    #     'source' : 'login',
    #     'timestamp' : timestamp,
    #     'timestamp_secret' : secret,
    #       })
    #     print(req.text)

    def login(self):

        code = self.session.get("https://github.com/login/").text
        get_data = GetData()
        token = get_data.getData(code,'<input type="hidden" name="authenticity_token" value=',' />')
        timestamp = get_data.getData(code,'<input type="hidden" name="timestamp" value="',' />')
        secret = get_data.getData(code,'<input type="hidden" name="timestamp_secret" value=',' />')
        post = {'commit': 'Sign+in',
                'authenticity_token': token,
                'login': 'lrmchi52894@chacuo.net',
                'password': '43WxpAap2eguetm',
                'trusted_device': '',
                'webauthn-support': 'supported',
                'webauthn-iuvpaa-support': 'unsupported',
                'return_to': '',
                'allow_signup': '',
                'client_id': '',
                'integration': '',
                'required_field_6913': '',
                'timestamp': timestamp,
                'timestamp_secret': secret
                }

        req = requests.post('https://github.com/login/',data = post)
        print(req.text)
